// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0

// FIXME: Skip embedding test on C++ and NodeJS since ComponentFactory is not
// implemented there!
//ignore: cpp,js,pyi

import { Button } from "std-widgets.slint";

component Container {
    in property<component-factory> c1 <=> cont1.component-factory;

    cont1 := ComponentContainer { }
}

export component TestCase inherits Rectangle {

    in property<component-factory> c1;
    out property<bool> outside-focus <=> outside.has-focus;

    outside := Button { text: "Outside button"; }

    Container {
        c1 <=> root.c1;
    }
}

/*
```cpp
// ComponentFactory not supported yet!
```

```rust
let factory = slint::ComponentFactory::new(|ctx| {

    let compiler = slint_interpreter::Compiler::new();
    let e = spin_on::spin_on(compiler.build_from_source(
        r#"import { Button } from "std-widgets.slint";

export component E1 inherits Rectangle {
    background: Colors.red;
    forward-focus: b;
    b := Button {
        text: "red";
    }
}"#.into(),
        std::path::PathBuf::from("embedded.slint"),
     )).component("E1").unwrap();
     e.create_embedded(ctx).ok()
});

let instance = TestCase::new().unwrap();
assert!(!instance.get_outside_focus()); // Nothing has focus be default
slint_testing::send_keyboard_string_sequence(&instance, "\t");
assert!(instance.get_outside_focus()); // The outside button is the only thing
                                       // accepting focus at this point.

instance.set_c1(factory);

assert!(instance.get_outside_focus()); // embedding does not move the focus

// focus the two embedded buttons:
slint_testing::send_keyboard_string_sequence(&instance, "\t");
assert!(!instance.get_outside_focus());

// Go back to outside button
slint_testing::send_keyboard_string_sequence(&instance, "\t");
assert!(instance.get_outside_focus());

// Focus backwards over the embedded buttons
slint_testing::send_keyboard_string_sequence(&instance, "\u{0019}");
assert!(!instance.get_outside_focus());

slint_testing::send_keyboard_string_sequence(&instance, "\u{0019}");
assert!(instance.get_outside_focus());
```

```js
var _instance = new slint.TestCase();
```
*/
